from LeetCoder import *


class Solution:
    def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]:
        n = len(A)
        h = [0] * (n + 1)
        ans = [0] * n
        for i in range(n):
            a, b = A[i], B[i]
            ans[i] = ans[i - 1] if i > 0 else 0
            if a == b:
                ans[i] += 1
                continue
            h[a] += 1
            h[b] -= 1
            if h[a] == 0:
                ans[i] += 1
            if h[b] == 0:
                ans[i] += 1

        return ans


s = Solution()
print(s.findThePrefixCommonArray(A=[1, 3, 2, 4], B=[3, 1, 2, 4]))
print(s.findThePrefixCommonArray(A=[2, 3, 1], B=[3, 1, 2]))
